<template>
  <el-dialog :visible.sync="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" :label-width="$i18n.locale === 'en-US' ? '120px' : '80px'">
          <el-form-item label="现金类型 1,消费账户 2.现金账户 3.伯乐收益 4.批发收益 5.线下充值.6手动补单现金 7.手动补单消费,8消费转现金,9现金转消费,10现金提现到银行卡,11提现拒绝,12使用优惠券,13批发消费减少,14批发消费增加 ,15等级级差奖励,16奖励转现金,17代理奖励,18库存转交易余额，19交易余额记录 20 销售奖,21手动补单奖励，22手动补单交易，23手动补单团队业绩24奖励账户提现手续费25奖励账户提现26消费账户提现27消费账户提现费用28提现额度控制29手续费退回,30领导奖" prop="type">
          <el-input v-model="dataForm.type" placeholder="现金类型 1,消费账户 2.现金账户 3.伯乐收益 4.批发收益 5.线下充值.6手动补单现金 7.手动补单消费,8消费转现金,9现金转消费,10现金提现到银行卡,11提现拒绝,12使用优惠券,13批发消费减少,14批发消费增加 ,15等级级差奖励,16奖励转现金,17代理奖励,18库存转交易余额，19交易余额记录 20 销售奖,21手动补单奖励，22手动补单交易，23手动补单团队业绩24奖励账户提现手续费25奖励账户提现26消费账户提现27消费账户提现费用28提现额度控制29手续费退回,30领导奖"></el-input>
      </el-form-item>
          <el-form-item label="发起用户ID 0为平台" prop="fromId">
          <el-input v-model="dataForm.fromId" placeholder="发起用户ID 0为平台"></el-input>
      </el-form-item>
          <el-form-item label="目标用户ID 0为平台" prop="userId">
          <el-input v-model="dataForm.userId" placeholder="目标用户ID 0为平台"></el-input>
      </el-form-item>
          <el-form-item label="对应订单号" prop="orderNo">
          <el-input v-model="dataForm.orderNo" placeholder="对应订单号"></el-input>
      </el-form-item>
          <el-form-item label="操作前的金额" prop="preCash">
          <el-input v-model="dataForm.preCash" placeholder="操作前的金额"></el-input>
      </el-form-item>
          <el-form-item label="流水标志 -1减少 1增加" prop="cashType">
          <el-input v-model="dataForm.cashType" placeholder="流水标志 -1减少 1增加"></el-input>
      </el-form-item>
          <el-form-item label="变动金额" prop="cash">
          <el-input v-model="dataForm.cash" placeholder="变动金额"></el-input>
      </el-form-item>
          <el-form-item label="备注" prop="remark">
          <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
      </el-form-item>
          <el-form-item label="有效状态 1有效-1删除" prop="dataFlag">
          <el-input v-model="dataForm.dataFlag" placeholder="有效状态 1有效-1删除"></el-input>
      </el-form-item>
          <el-form-item label="创建时间" prop="createTime">
          <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
      </el-form-item>
      </el-form>
    <template slot="footer">
      <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button>
    </template>
  </el-dialog>
</template>

<script>
import debounce from 'lodash/debounce'
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        id: '',
        type: '',
        fromId: '',
        userId: '',
        orderNo: '',
        preCash: '',
        cashType: '',
        cash: '',
        remark: '',
        dataFlag: '',
        createTime: ''
      }
    }
  },
  computed: {
    dataRule () {
      return {
        type: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        fromId: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        userId: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        orderNo: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        preCash: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        cashType: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        cash: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        remark: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        dataFlag: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        createTime: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init () {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.getInfo()
        }
      })
    },
    // 获取信息
    getInfo () {
      this.$http.get(`/demo/xlslogcash/${this.dataForm.id}`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.dataForm = {
          ...this.dataForm,
          ...res.data
        }
      }).catch(() => {})
    },
    // 表单提交
    dataFormSubmitHandle: debounce(function () {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return false
        }
        this.$http[!this.dataForm.id ? 'post' : 'put']('/demo/xlslogcash/', this.dataForm).then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        }).catch(() => {})
      })
    }, 1000, { 'leading': true, 'trailing': false })
  }
}
</script>
